package com.cwh.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cwh.entity.Baoxiaobill;
import com.cwh.entity.BaoxiaobillExample;
import com.cwh.entity.BaoxiaobillExample.Criteria;
import com.cwh.mapper.BaoxiaobillMapper;
import com.cwh.service.BaoxiaobillService;


@Service
public class BaoxiaobillServiceImpl implements BaoxiaobillService {
	
	@Autowired
	private BaoxiaobillMapper baoxiaobillMapper;
	
	
	
	//查看所有报销记录
	@Override
	public List<Baoxiaobill> findBoxiaobillList() {
		List<Baoxiaobill> selectByExample = baoxiaobillMapper.selectByExample(null);
		return selectByExample;
	}
	
	//根据userId获取myBaoxiaoBill表对应的报销记录
	@Override
	public List<Baoxiaobill> findBaoxiaobillListByUserId(long id) {
		BaoxiaobillExample example=new BaoxiaobillExample();
		Criteria createCriteria = example.createCriteria();
		createCriteria.andUserIdEqualTo((int)id);
		List<Baoxiaobill> baoxiaobillList = baoxiaobillMapper.selectByExample(example);
		return baoxiaobillList;
	}
	
	//在报销表插入数据后，并能获取插入后的id
	@Override
	public void inserBaoxiaobillReturnId(Baoxiaobill baoxiaobill) {
		baoxiaobillMapper.inserBaoxiaobillReturnId(baoxiaobill);
	}
	
	//根据报销表id查找Baoxiaobill记录
	@Override
	public Baoxiaobill findBaoxiaobillById(int id) {
		BaoxiaobillExample example=new BaoxiaobillExample();
		Criteria createCriteria = example.createCriteria();
		createCriteria.andIdEqualTo(id);
		List<Baoxiaobill> baoxiaobillList = baoxiaobillMapper.selectByExample(example);
		
		Baoxiaobill baoxiaobill=null;
		if(baoxiaobillList!=null&&baoxiaobillList.size()>0) {
			baoxiaobill=baoxiaobillList.get(0);
		}
		return baoxiaobill;
	}
	
	//根据实体更新
	@Override
	public void updateBaoxiaobill(Baoxiaobill baoxiaobill) {
		baoxiaobillMapper.updateByPrimaryKey(baoxiaobill);
		
	}
	//根据报销表id删除报销表记录
	@Override
	public void deleteBaoxiaobillById(Integer id) {
		baoxiaobillMapper.deleteByPrimaryKey(id);
		
	}
	

}
